-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mock: in order mock calls #1637
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a unit test, please.
unit test added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Positive and negative tests, nice one. 👍 Just a couple of small comments.
mock/mock_test.go
Outdated
c, | ||
) | ||
|
||
require.Equal(t, []*Call{b, c}, mockedService.ExpectedCalls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is testing the implementation. A cost effective test would only test the behaviour, as you are doing just fine after this line.
If you remove this assertion then we are free to change the implementation of the intended behaviour without breaking the test. It also removes the need to declare b
and c
, so the test can be written as InOrder
is intended to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it's just comparing pointer values. If InOrder did literally nothing then that assertion would still pass.
(requested changes applied)
Good comments, thanks! Requested changes applied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, should be helpful to all the developers moving from gomock. I'll give some time for other maintainers to review before I merge.
Ah you beat me to it, thanks! And missed that existing PR |
Hello, any ETA on merging this PR? |
Thanks @ReyOrtiz. This can be consumed now by gomock expats with: |
Thanks @brackendawson for all the help! 🙏 |
Summary
Add helper method to declare the order of the mock calls.
Changes
InOrder(calls ...*Call)
helper method to declare the order of mock calls by callingNotBefore()
Motivation
This is probably the only feature I miss from
gomock.InOrder()
, it is more intuitive and cleaner to declare the order of the mock calls. Probably most cases can be satisfied with this method.Related issues
Closes #1639